package com.xidian.zhiancloud.service.accidentManage;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xidian.zhiancloud.dao.MissAccidentMessageMapper;
import com.xidian.zhiancloud.model.MissAccidentMessage;
import com.xidian.zhiancloud.qo.accidentmessage.MissAccidentQO;
import com.xidian.zhiancloud.vo.accidentmessage.MissAccidentVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 未遂事件信息管理
 * @ClassName MissAccidentService
 * @Description TODO
 * @Author Halo
 **/
@Service
public class MissAccidentService extends ServiceImpl<MissAccidentMessageMapper, MissAccidentMessage>
        implements IService<MissAccidentMessage> {

    @Resource
    private MissAccidentMessageMapper missAccidentMessageMapper;

    /**
     * 条件查询
     * @param missAccidentQO
     * @return
     */
    public IPage<MissAccidentVO> getListByQO(MissAccidentQO missAccidentQO){
        Page<MissAccidentVO> page = new Page<>(missAccidentQO.getCurrent(),missAccidentQO.getSize());

        //排序
        OrderItem orderItem = new OrderItem();
        orderItem.setColumn("create_time").setAsc(false);
        page.getOrders().add(orderItem);

        IPage<MissAccidentVO> list = missAccidentMessageMapper.getListByQO(page, missAccidentQO);
        list.getRecords().forEach(
                vo -> {
                    vo.setCreatorName(vo.getCreatorName() == null ? "该用户不存在" : vo.getCreatorName());
                    vo.setDepartmentName(vo.getDepartmentName() == null ? "该用户不存在" : vo.getDepartmentName());
                }
        );

        return list;
    }
}
